<template>
	<view class="pageBox">
		<view class="main">
			<view class="mainItem flex-between" @click="onAvatar">
				<view class="title">
					头像
				</view>
				<view class="right flex-row">
					<image class="avatar" :src="user.avatar" mode=""></image>
					<image class="arrowRight" src="http://www.bobei.shop/static/home/arrowRight.png" mode=""></image>
				</view>
			</view>

			<view class="mainItem flex-between" @click="goNickname">
				<view class="title">
					昵称
				</view>
				<view class="right flex-row">
					<view class="rightText">
						{{user.nickname}}
					</view>
					<image class="arrowRight" src="http://www.bobei.shop/static/home/arrowRight.png" mode=""></image>
				</view>
			</view>
			<view class="mainItem flex-between">
				<view class="title">
					ID
				</view>
				<view class="right flex-row">
					<view class="rightText">
						{{ user.id }}
					</view>
				</view>
			</view>
			<view class="mainItem flex-between">
				<view class="title">
					联系电话
				</view>
				<view class="right flex-row">
					<view class="rightText">
						{{ user.account }}
					</view>
				</view>
			</view>
			<view class="list">
				<view class="listItem" v-for="item in list" :key="item.id">
					<view class="top flex-row">
						<view class="defaultText flex-center" v-if="item.status == 1">
							默认
						</view>
						<view class="topR">
							{{item.name}}&nbsp;&nbsp;&nbsp;&nbsp;{{item.mobile}}
						</view>
						<view class="check-icon" v-if="isSelect" @click="onSelectItem(item)">
							<image class="check-icon-img" src="http://www.bobei.shop/static/login/choosed.png" v-if="selectId == item.id">
							</image>
							<image class="check-icon-img" src="http://www.bobei.shop/static/login/choose.png" v-else></image>
						</view>
					</view>
			
				<!-- 	<view class="center">
						{{item.address}}
					</view> -->
			
					<view class="bom flex-between">
						<view class="bomL">
							{{item.province}}{{item.city}}{{item.area}}{{item.address}}
							<!-- {{item.name}}&nbsp;&nbsp;&nbsp;&nbsp;{{item.mobile}} -->
						</view>
						<view class="bomR flex">
							<image class="icon" src="http://www.bobei.shop/static/third/my/Slice 163.png" mode=""
								@click.stop="goEdite(item.id)"></image>
							<image class="icon" src="http://www.bobei.shop/static/third/my/Slice 164.png" mode="" @click.stop="onDelBtn(item.id)">
							</image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<my-popup-tips :showTips="showTips">
			<view class="tipsBox">
				<view class="tipsTitle flex-center">
					提示
				</view>
		
				<view class="tipsText flex-center">
					确定要删除该地址吗？
				</view>
		
				<view class="tipsBtnBox flex-between">
					<button class="tipsCloseBtn" :plain="true" @click="onTipsCloseBtn">取消</button>
					<button class="tipsSureBtn" :plain="true" @click="onTipsSureBtn">确定</button>
				</view>
			</view>
		</my-popup-tips>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {},
				showTips: false,
				list: [],
				temp: "",
				isSelect: false,
				selectId: "",
				eventChannel: null,
				
				
			}
		},
		onShow() {
			this.getInfo()
			this.getList();
			
		},
		
		methods: {
		
			onAvatar() {
				let that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: function(res) {
						// console.log(res)
						// console.log(JSON.stringify(res.tempFilePaths));
						that.$upload({
							data: {
								filePath: res.tempFilePaths[0],
							}
						}).then(images => {
							// console.log(images);
							that.user.avatar = images.file
							that.$post({
								module: 'User',
								interface: 1001,
								data: that.user
							}).then((resss) => {
								uni.showToast({
									title: resss.message,
									icon: "none",
									duration: 1500,
								})
							})
						})
					}
				});
			},
			goNickname() {
				uni.navigateTo({
					url: '/setting/nickname'
				})
			},
			getInfo() {
				this.$post({
					module: 'User',
					interface: 1000,

				}).then(res => {
					this.user = res
				})
			},
			onDelBtn(id) {
				this.temp = id;
				this.showTips = true;
			},
			onTipsCloseBtn() {
				this.showTips = false;
			},
			onTipsSureBtn() {
				this.showTips = false;
				this.$post({
					module: "User",
					interface: "6002",
					data: {
						id: this.temp
					}
				}).then(() => {
					uni.showToast({
						title: "删除成功",
						icon: "none",
						duration: 1500,
					})
					setTimeout(() => this.getList(), 1000)
				})
			},
			goEdite(id = "") {
				uni.navigateTo({
					url: '/serviceCenter/addressEdite?id=' + id,
				})
			},
			getList() {
				this.$post({
					module: "User",
					interface: "6000"
				}).then(res => {
					// // console.log("地址列表", res)
					this.list = res;
				})
			},
			onSelectItem(item) {
				this.eventChannel.emit("select", item);
				uni.navigateBack();
			}
		},
		
	}
</script>

<style scoped lang="scss">
	.pageBox {
		width: 100%;
		min-height: calc(100vh - var(--window-top));
		// background: #f9f9f9;
		padding-top: 32rpx;
		.list {
			padding: 0 30rpx 120rpx;
		
			.listItem {
				padding: 32rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 2rpx 8rpx 0rpx rgba(212,212,212,0.25);
				border-radius: 24rpx;
				margin-bottom: 24rpx;
				.top {
					.defaultText {
						width: 60rpx;
						height: 24rpx;
						background: rgba(242,97,95,0.2965);
						border-radius: 8rpx;
						font-size: 16rpx;
						color: #F2615F;
						margin-right: 10rpx;
						
					}
		
					.topR {
						flex: 1;
						font-size: 36rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 600;
						color: #000000;
						line-height: 40rpx;
						margin-bottom: 10rpx;
					}
		
					.check-icon {
						width: 44rpx;
						height: 44rpx;
		
						.check-icon-img {
							width: 100%;
							height: 100%;
							vertical-align: middle;
						}
					}
				}
		
				.center {
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #000000;
					line-height: 40rpx;
					margin-top: 10rpx;
				}
		
				.bom {
					.bomL {
						font-size: 28rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #afa9b0;
						line-height: 40rpx;
					}
		
					.bomR {
						margin-top: 32rpx;
		
						.icon {
							width: 32rpx;
							height: 32rpx;
							margin-left: 32rpx;
		
						}
					}
				}
			}
		}
		.tipsBox {
			width: 550rpx;
			background: #FFFFFF;
			border-radius: 32rpx;
			padding: 64rpx 48rpx;
		
			.tipsTitle {
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #000000;
				line-height: 40rpx;
			}
		
			.tipsText {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #736464;
				line-height: 40rpx;
				margin-top: 48rpx;
			}
		
			.tipsBtnBox {
				width: 100%;
				margin-top: 90rpx;
		
				button {
					padding: 0;
					margin: 0;
					width: 200rpx;
					height: 72rpx;
					border-radius: 52rpx;
					font-size: 28rpx;
				}
		
				.tipsCloseBtn {
					color: #F2615F;
					border: 2rpx solid #F2615F;
				}
		
				.tipsSureBtn {
					color: #ffffff;
					border: none;
					background: #F2615F;
				}
			}
		}

		.main {
			width: 100%;
			background: linear-gradient(180deg, #FFF5F4 0%, #FFFFFF 14%);
			border-radius: 24rpx 24rpx 0rpx 0rpx;

			.mainItem {
				width: 100%;
				padding: 32rpx;

				.title {
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 600;
					color: #000000;
					line-height: 40rpx;
				}

				.right {
					.avatar {
						width: 76rpx;
						height: 76rpx;
						border-radius: 50%;
					}

					.rightText {
						font-size: 32rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
						line-height: 40rpx;
					}
				}

				.arrowRight {
					width: 28rpx;
					height: 28rpx;
					margin-left: 20rpx;
				}
			}
		}
	}
</style>
